package com.atguigu.vod.controller;

import com.atguigu.commonutils.R;
import com.atguigu.vod.service.VodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/eduvod/video")
@CrossOrigin
public class VodController {

    @Autowired
    private VodService vodService;

    //上传视频到阿里云
    @PostMapping("uploadAliyunVideo")
    public R uploadAliyunVideo(MultipartFile file) {

        String videoId = vodService.upLoadAliyunVideo(file);

        return R.ok().data("data",videoId);
    }

    //根据id删除单个视频
    @DeleteMapping("deleteVideoById/{videoId}")
    public R deleteVideoById(@PathVariable String videoId) {

        vodService.deleteAliyunVideoById(videoId);

        return R.ok().message("删除视频成功");
    }

    //根据课程id删除多个阿里云视频
    @DeleteMapping("deleteBatch")
    public R deleteBatch(@RequestParam("videoIdList") List<String> videoIdList ) {

        vodService.deleteAliyunVideoByIdList(videoIdList);

        return R.ok();
    }
}
